home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: recoverUndo.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:55 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "link.h"
- #include "lsn.h"
- #include "latch.h"
- #include "bf.h"
- #include "volume.h"
- #include "trans.h"
- #include "openlog.h"
- #include "logrecs.h"
- #include "threadstate.h"
- #include "trans_extfuncs.h"
- #include "trans_intfuncs.h"
- #include "recover_intfuncs.h"
- #include "lm_extfuncs.h"
- #include "log_extfuncs.h"
- #include "thread_funcs.h"
- #include "thread_globals.h"
- #include "trans_globals.h"
- #include "recover_globals.h"
-
-
- void
- recoverUndo (
-
- LSNOFFSET lastLSN
- )
- {
-
- TRANSREC *transRec; /* current transaction */
- TRANSREC *nextTransRec; /* next transaction to undo */
- int maxFork; /* max forked undo threads */
-
-
- TRACE(TR_TRANS, TR_LEVEL_1);
-
- initializeList(&(RecoverUndoWaitList));
-
- /* sort the transaction list by lastLSN */
- sortUndoList(&ActiveTransList, lastLSN);
-
- /*
- * At most fork only half of the available threads
- */
- maxFork = (NumThreads-CONST_THREADS)/2;
- if (maxFork < 1) {
- fprintf(sm_ErrorStream, "SERVER ERROR: insufficient threads to perform undo phase\n");
- SM_ERROR(TYPE_STOP, esmNOFREETHREAD);
- }
-
- /* search down the list */
- UndoForkCount = 0;
- nextTransRec = (TRANSREC *) FIRST_LIST_ELEMENT( &ActiveTransList );
- while (nextTransRec != NULL) {
-
- /* get the transaction with the largest nextUndoLSN */
- transRec = nextTransRec;
- nextTransRec = (TRANSREC *) NEXT_LIST_ELEMENT( &(nextTransRec->activeTransList) );
-
- /*
- * check the entry magic number
- */
- CHECK_TRANSREC_MAGIC(transRec);
-
- /*
- * if the transaction is a distributed transaction then
- * it cannot be thrown away because it must be past the
- * prepared state
- */
- if (LIST_MEMBER( &(transRec->distrTransList)))
- continue;
-
- /*
- * If the transaction state is active, then abort it, otherwise
- * just remove it from the active list.
- */
- switch (transRec->transState) {
- case T_RECOVER:
- /*
- * Record that the transaction is being aborted, but the
- * transaction is one that was left running at the time
- * of the crash, so its state is T_RECOVER. If it is
- * set to T_ABORT then it looks like it is a transaction
- * started after the system restarted.
- */
- transRec->transState = T_RECOVER;
- transRec->intent = T_ABORT;
-
- /* fork a thread to undo the transaction */
- SM_ASSERT(LEVEL_3, sizeof(FOUR) == sizeof(transRec));
- threadFork(T_PARENT, (PFI) recoverUndoTrans, 1, (FOUR*) &(transRec));
- UndoForkCount++;
-
- /*
- * If we have forked too many threads, wait until one
- * currently active undo completes.
- */
- if (UndoForkCount == maxFork) {
- if (waitList(&RecoverUndoWaitList, THREAD_RECOVER_UNDO_WAIT)) {
- SM_ERROR(TYPE_CRASH, esmINTERNAL);
- }
- SM_ASSERT(LEVEL_3, UndoForkCount < maxFork);
- }
-
- break;
- case T_COMMIT:
-
- /* free the structures */
- freeTransVolRecs(transRec);
-
- /* give back the transaction record */
- freeTransRec(transRec);
-
- break;
-
- default:
- #ifdef DEBUG
- TRPRINT( TR_RECOVER, TR_LEVEL_1,
- ("UNEXPECTED TRANS STATE: 0x%x for transaction # %d",
- transRec->transState, transRec->tid));
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- continue;
- #else
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- #endif DEBUG
- }
- }
-
- /* wait for all undos to complete */
- while (UndoForkCount > 0) {
- if (waitList(&RecoverUndoWaitList, THREAD_RECOVER_UNDO_WAIT)) {
- SM_ERROR(TYPE_CRASH, esmINTERNAL);
- }
- }
- SM_ASSERT(LEVEL_3, UndoForkCount == 0);
-
- /*
- * no longer true because of the existence of distr trans
- * SM_ASSERT(LEVEL_1, LIST_EMPTY( &(ActiveTransList) ));
- */
- }
-